<?php
namespace app\forum\controller;
use app\forum\controller\SiteController;
/**
 * 帖子搜索
 */
class SearchController extends SiteController {

	/**
     * 主页
     */
    public function index(){

        $keyword = request('request.keyword');
        //解析关键词
        $keyword = len($keyword,0,20);
        $keywords = preg_replace ('/\s+/',' ',$keyword); 
        $keywords=explode(" ",$keywords);
        if(empty($keywords[0])){
            $this->error('没有输入关键词！');
        }
        $where = array();
        $where['A.status'] = 1;
        $where[] = ' (A.title like "%'.$keyword.'%") OR  (A.keywords like "%'.$keyword.'%")  OR  (A.description like "%'.$keyword.'%") ';
        $pageList = target('Thread')->page(20)->loadList($where,10,'A.post_time desc,A.thread_id desc');
        $this->pager = target('Thread')->pager;
        $this->crumb[] = array('url'=>url('index',array('page_id'=>$pageId)),'name'=>'搜索');
        $pageMaps = array();
        $pageMaps['keyword'] = $keyword;
        $page = $this->getPageShow($pageMaps);
        $this->assign('pageList', $pageList);
        $this->assign('page', $page);
        $this->assign('keyword', $keyword);
        $this->siteDisplay();
    }
}